home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / xf2.3-p / xf2 / xf2.3 / src / xfsaveMisc.tcl < prev    next >
Encoding:
Text File  |  1994-05-22  |  24.4 KB  |  810 lines

  1. # Program: xf
  2. # Description: save misc stuff (almost everything :-)
  3. #
  4. # $Header: xfsaveMisc.tcl[2.5] Wed Mar 10 12:08:20 1993 garfield@garfield frozen $
  5.  
  6. ##########
  7. # Procedure: XFSaveBind
  8. # Description: save bindings
  9. # Arguments: xfOutFile - the output descriptor
  10. #            xfW - the widget, or widget class
  11. #            xfNoLeftOffset - don't indent output
  12. # Returns: none
  13. # Sideeffects: none
  14. ##########
  15. proc XFSaveBind {xfOutFile xfW {xfNoLeftOffset 0}} {
  16.   global xfConf
  17.  
  18.   # get list of bindings
  19.   set xfTmpString ""
  20.   if {$xfNoLeftOffset} {
  21.     set xfLeftOffset ""
  22.   } {
  23.     set xfLeftOffset "  "
  24.   }
  25.   foreach xfCounter [lsort [bind $xfW]] {
  26.     if {[XFMiscCorrectLevel bindsave [bind $xfW $xfCounter]]} {
  27.       if {$xfConf(encloseBinding)} {
  28.         append xfTmpString "\n${xfLeftOffset}bind $xfW $xfCounter \{[bind $xfW $xfCounter]\}"
  29.       } {
  30.         append xfTmpString "\n${xfLeftOffset}bind $xfW $xfCounter \"[bind $xfW $xfCounter]\""
  31.       }
  32.     }
  33.   }
  34.   if {"$xfTmpString" != ""} {
  35.     puts $xfOutFile "${xfLeftOffset}# bindings$xfTmpString"
  36.   }
  37. }
  38.  
  39. ##########
  40. # Procedure: XFSaveComment
  41. # Description: save comment
  42. # Arguments: xfOutFile - the output descriptor
  43. #            xfType - the comment type (file, module, proc)
  44. #            xfName - the name (either filename, modulename, procname)
  45. # Returns: none
  46. # Sideeffects: none
  47. ##########
  48. proc XFSaveComment {xfOutFile xfType xfName} {
  49.   global env
  50.   global tkVersion
  51.   global xfConf
  52.   global xfComment
  53.   global xfVersionNr
  54.  
  55.   set xfTmpComment ""
  56.   case $xfType in {
  57.     {file} {
  58.       set xfTmpComment $xfComment(file)
  59.       regsub -all {\$programName} $xfTmpComment $xfName xfTmpComment
  60.     }
  61.     {module} {
  62.       set xfTmpComment $xfComment(module)
  63.       regsub -all {\$moduleName} $xfTmpComment $xfName xfTmpComment
  64.     }
  65.     {template} {
  66.       set xfTmpComment $xfComment(template)
  67.       regsub -all {\$templateName} $xfTmpComment $xfName xfTmpComment
  68.     }
  69.     {proc} {
  70.       set xfTmpComment $xfComment(proc)
  71.       regsub -all {\$procedureName} $xfTmpComment $xfName xfTmpComment
  72.     }
  73.   }
  74.   regsub -all {\$interpreter} $xfTmpComment $xfConf(interpreter) xfTmpComment
  75.   if {[info exists env(USER)]} {
  76.     regsub -all {\$user} $xfTmpComment $env(USER) xfTmpComment
  77.   }
  78.   if {[info exists env(LOGNAME)]} {
  79.     regsub -all {\$logname} $xfTmpComment $env(LOGNAME) xfTmpComment
  80.   }
  81.   if {[info exists env(HOST)]} {
  82.     regsub -all {\$host} $xfTmpComment $env(HOST) xfTmpComment
  83.   }
  84.   regsub -all {\$tkVersion} $xfTmpComment $tkVersion xfTmpComment
  85.   regsub -all {\$tclVersion} $xfTmpComment [info tclversion] xfTmpComment
  86.   regsub -all {\$xfVersion} $xfTmpComment $xfVersionNr xfTmpComment
  87.   regsub -all {\$magicCookie} $xfTmpComment Tcl/Tk/XF xfTmpComment
  88.   puts $xfOutFile "$xfTmpComment"
  89. }
  90.  
  91. ##########
  92. # Procedure: XFSaveGlobals
  93. # Description: save global variables
  94. # Arguments: xfOutFile - the output descriptor
  95. #            xfSavePlain - save the output as plain tcl file
  96. # Returns: none
  97. # Sideeffects: none
  98. ##########
  99. proc XFSaveGlobals {xfOutFile {xfSavePlain 0}} {
  100.   global xfAppDefToplevels
  101.  
  102.   if {!$xfSavePlain} {
  103.     set leftOffset "  "
  104.     puts $xfOutFile "\n# initialize global variables"
  105.     puts $xfOutFile "proc InitGlobals {} {"
  106.     # make interpreter happy }
  107.   } {
  108.     set leftOffset ""
  109.     puts $xfOutFile "\n# initialize global variables"
  110.   }
  111.   foreach xfCounter [lsort [info globals]] {
  112.     if {[XFMiscIsXFElement $xfCounter]} {
  113.       continue
  114.     }
  115.     if {[string match "xf*" $xfCounter]} {
  116.       continue
  117.     }
  118.     if {"[string trim $xfCounter]" != ""} {
  119.       global $xfCounter
  120.       puts $xfOutFile "${leftOffset}global \{$xfCounter\}"
  121.     
  122.       # missing array handling by: Tim MaxKenzie
  123.       # (sorry I could not keep my hands from your patch Tim :-)
  124.       if {[catch "array names $xfCounter" xfResult]} {
  125.         puts $xfOutFile "${leftOffset}set \{$xfCounter\} \{[set $xfCounter]\}"
  126.       } {
  127.         foreach xfCounter2 [lsort [array names $xfCounter]] {
  128.           set xfArrayName ""
  129.           append xfArrayName $xfCounter ( $xfCounter2 )
  130.           puts $xfOutFile "${leftOffset}set \{$xfArrayName\} \{[set $xfArrayName]\}"
  131.         }
  132.       }
  133.     }
  134.   }
  135.   puts $xfOutFile "\n${leftOffset}# please don't modify the following"
  136.   puts $xfOutFile "${leftOffset}# variables. They are needed by xf."
  137.   foreach xfCounter "autoLoadList internalAliasList moduleList preloadList symbolicName xfWmSetPosition xfWmSetSize" {
  138.     global $xfCounter
  139.     puts $xfOutFile "${leftOffset}global \{$xfCounter\}"
  140.     if {[catch "array names $xfCounter" xfResult]} {
  141.       puts $xfOutFile "${leftOffset}set \{$xfCounter\} \{[set $xfCounter]\}"
  142.     } {
  143.       foreach xfCounter2 [lsort [array names $xfCounter]] {
  144.         set xfArrayName ""
  145.         append xfArrayName $xfCounter ( $xfCounter2 )
  146.         puts $xfOutFile "${leftOffset}set \{$xfArrayName\} \{[set $xfArrayName]\}"
  147.       }
  148.     }
  149.   }
  150.   set xfTmpValue ""
  151.   foreach xfCounter $xfAppDefToplevels {
  152.     if {"[info commands $xfCounter]" != "" ||
  153.         "[info commands ShowWindow$xfCounter]" != ""} {
  154.       append xfTmpValue "$xfCounter "
  155.     }
  156.   }
  157.   puts $xfOutFile "${leftOffset}global \{xfAppDefToplevels\}"
  158.   puts $xfOutFile "${leftOffset}set \{xfAppDefToplevels\} \{$xfTmpValue\}"
  159.   if {!$xfSavePlain} {
  160.     # make interpreter happy {
  161.     puts $xfOutFile "}"
  162.   }
  163. }
  164.  
  165. ##########
  166. # Procedure: XFSaveMenubarTraversal
  167. # Description: save menubar traversal code
  168. # Arguments: xfOutFile - the output descriptor
  169. # Returns: none
  170. # Sideeffects: none
  171. ##########
  172. proc XFSaveMenubarTraversal {xfOutFile} {
  173.   global xfMisc
  174.  
  175.   if {[llength $xfMisc(menuBarTraversalList)] > 0} {
  176.     puts $xfOutFile "\n  global tkVersion"
  177.     puts $xfOutFile "  if {\$tkVersion >= 3.0} {"
  178.     puts $xfOutFile "    tk_menuBar $xfMisc(menuBarTraversalList)"
  179.     puts $xfOutFile "  } {"
  180.     puts $xfOutFile "    tk_menus [winfo toplevel [lindex $xfMisc(menuBarTraversalList) 0]] [lrange $xfMisc(menuBarTraversalList) 1 end]"
  181.     puts $xfOutFile "  }"
  182.   }
  183. }
  184.  
  185. ##########
  186. # Procedure: XFSavePack
  187. # Description: save packing
  188. # Arguments: xfOutFile - the output descriptor
  189. #            xfW - the widget
  190. # Returns: none
  191. # Sideeffects: none
  192. ##########
  193. proc XFSavePack {xfOutFile xfW} {
  194.   global xfConf
  195.  
  196.   if {$xfConf(newPacker)} {
  197.     # sugared version - makes pleasant output
  198.     set xfSlaves [pack slaves $xfW]
  199.     if {$xfSlaves != ""} {
  200.       set xfDefault(-anchor) center
  201.       set xfDefault(-expand) 0
  202.       set xfDefault(-fill) none
  203.       set xfDefault(-ipadx) 0
  204.       set xfDefault(-ipady) 0
  205.       set xfDefault(-padx) 0
  206.       set xfDefault(-pady) 0
  207.       set xfDefault(-side) top
  208.       puts $xfOutFile "\n  # pack master $xfW"
  209.       foreach xfSlave $xfSlaves {
  210.         if {![string match xf* [winfo name $xfSlave]]} {
  211.           set xfDefault(-in) [winfo parent $xfSlave]
  212.           set xfConfig [pack newinfo $xfSlave]
  213.           puts -nonewline $xfOutFile "  pack configure $xfSlave"
  214.           while {$xfConfig != ""} {
  215.             set xfKey [lindex $xfConfig 0]
  216.             set xfValue [lindex $xfConfig 1]
  217.             set xfConfig [lrange $xfConfig 2 end]
  218.             if {$xfValue != $xfDefault($xfKey)} {
  219.               puts -nonewline $xfOutFile " \\\n    $xfKey $xfValue"
  220.             }
  221.           }
  222.           puts $xfOutFile ""
  223.         }
  224.       }
  225.     }
  226.   } {
  227.     # get list of pack elements
  228.     set xfIgnore 0
  229.     set xfTmpString ""
  230.     set xfElementType 0
  231.     foreach xfCounter [pack info $xfW] {
  232.       if {$xfElementType == 0} {
  233.         if {[string match "xf*" [winfo name $xfCounter]]} {
  234.           set xfIgnore 1
  235.         } {
  236.           append xfTmpString " \\\n    $xfCounter"
  237.         }
  238.         set xfElementType 1
  239.       } {
  240.         if {$xfIgnore} {
  241.           set xfIgnore 0
  242.         } {
  243.           append xfTmpString " {$xfCounter}"
  244.         }
  245.         set xfElementType 0
  246.       }
  247.     }
  248.     if {"$xfTmpString" != ""} {
  249.       puts $xfOutFile "\n  # pack widget $xfW\n  pack append $xfW$xfTmpString"
  250.     }
  251.   }
  252. }
  253.  
  254. ##########
  255. # Procedure: XFSavePackOne
  256. # Description: save packing for one child
  257. # Arguments: xfOutFile - the output descriptor
  258. #            xfW - the widget
  259. #            xfSlave - the slave we want to pack
  260. #            xfSaveAsProc - this is for a procedure
  261. # Returns: none
  262. # Sideeffects: none
  263. ##########
  264. proc XFSavePackOne {xfOutFile xfW xfSlave {xfSaveAsProc 0}} {
  265.   global xfConf
  266.  
  267.   if {$xfConf(newPacker)} {
  268.     if {![catch {pack newinfo $xfSlave} xfInfo]} {
  269.       set xfDefault(-anchor) center
  270.       set xfDefault(-expand) 0
  271.       set xfDefault(-fill) none
  272.       set xfDefault(-ipadx) 0
  273.       set xfDefault(-ipady) 0
  274.       set xfDefault(-padx) 0
  275.       set xfDefault(-pady) 0
  276.       set xfDefault(-side) top
  277.       puts $xfOutFile "\n  # pack slave $xfSlave"
  278.       set xfDefault(-in) [winfo parent $xfSlave]
  279.       set xfConfig [pack newinfo $xfSlave]
  280.       puts -nonewline $xfOutFile "  pack configure $xfSlave"
  281.       while {$xfConfig != ""} {
  282.         set xfKey [lindex $xfConfig 0]
  283.         set xfValue [lindex $xfConfig 1]
  284.         set xfConfig [lrange $xfConfig 2 end]
  285.         if {$xfValue != $xfDefault($xfKey)} {
  286.           puts -nonewline $xfOutFile " \\\n    $xfKey $xfValue"
  287.         }
  288.       }
  289.       puts $xfOutFile ""
  290.     }
  291.   } {
  292.     # get list of pack elements
  293.     set xfTmpString ""
  294.     set xfElementType 0
  295.     set xfCurrentChld ""
  296.     foreach xfCounter [pack info $xfW] {
  297.       if {$xfElementType == 0} {
  298.         if {"$xfCounter" == "$xfSlave"} {
  299.           append xfTmpString " \\\n    $xfCounter"
  300.           set xfCurrentChld $xfCounter
  301.           set xfElementType 1
  302.         }
  303.       } {
  304.         if {"$xfCurrentChld" == "$xfSlave"} {
  305.           append xfTmpString " {$xfCounter}"
  306.           set xfElementType 0
  307.           break
  308.         }
  309.       }
  310.     }
  311.     if {"$xfTmpString" != ""} {
  312.       puts $xfOutFile "  # pack widgets\n  pack append $xfW$xfTmpString"
  313.     }
  314.   }
  315. }
  316.  
  317. ##########
  318. # Procedure: XFSavePlace
  319. # Description: save placing
  320. # Arguments: xfOutFile - the output descriptor
  321. #            xfW - the widget
  322. # Returns: none
  323. # Sideeffects: none
  324. ##########
  325. proc XFSavePlace {xfOutFile xfW} {
  326.   global tkVersion
  327.  
  328.   # get list of place elements
  329.   set xfTmpString ""
  330.   if {$tkVersion >= 3.0} {
  331.     foreach xfCounter [place slaves $xfW] {
  332.       if {![string match "xf*" [winfo name $xfCounter]]} {
  333.         append xfTmpString "\n  # place\n"
  334.         append xfTmpString "  place $xfCounter [place info $xfCounter]\n"
  335.       }
  336.     }
  337.   } {
  338.     foreach xfCounter [place dependents $xfW] {
  339.       if {![string match "xf*" [winfo name $xfCounter]]} {
  340.         append xfTmpString "\n  # place\n"
  341.         append xfTmpString "  place $xfCounter [place info $xfCounter]\n"
  342.       }
  343.     }
  344.   }
  345.   if {"$xfTmpString" != ""} {
  346.     puts $xfOutFile "$xfTmpString"
  347.   }
  348. }
  349.  
  350. ##########
  351. # Procedure: XFSavePlaceOne
  352. # Description: save placing for one child
  353. # Arguments: xfOutFile - the output descriptor
  354. #            xfW - the widget
  355. #            xfSlave - the slave we want to place
  356. #            xfSaveAsProc - this is for a procedure
  357. # Returns: none
  358. # Sideeffects: none
  359. ##########
  360. proc XFSavePlaceOne {xfOutFile xfW xfSlave {xfSaveAsProc 0}} {
  361.   global tkVersion
  362.  
  363.   # get list of place elements
  364.   set xfTmpString ""
  365.   if {$tkVersion >= 3.0} {
  366.     foreach xfCounter [place slaves $xfW] {
  367.       if {"$xfCounter" == "$xfSlave"} {
  368.         append xfTmpString "\n  # place\n"
  369.         append xfTmpString "  place $xfCounter [place info $xfCounter]\n"
  370.         break
  371.       }
  372.     }
  373.   } {
  374.     foreach xfCounter [place dependents $xfW] {
  375.       if {"$xfCounter" == "$xfSlave"} {
  376.         append xfTmpString "\n  # place\n"
  377.         append xfTmpString "  place $xfCounter [place info $xfCounter]\n"
  378.         break
  379.       }
  380.     }
  381.   }
  382.   if {"$xfTmpString" != ""} {
  383.     puts $xfOutFile "$xfTmpString"
  384.   }
  385. }
  386.  
  387. ##########
  388. # Procedure: XFSaveProc
  389. # Description: save named procedure
  390. # Arguments: xfOutFile - the output descriptor
  391. #            xfProcName - the procedure name
  392. # Returns: none
  393. # Sideeffects: none
  394. ##########
  395. proc XFSaveProc {xfOutFile xfProcName} {
  396.  
  397.   # get arg list for procedure
  398.   set xfArgList [info args $xfProcName]
  399.   set xfArguments ""
  400.   foreach xfArg $xfArgList {
  401.     if {[info default $xfProcName $xfArg xfDefault]} {
  402.       append xfArguments " \{$xfArg \"$xfDefault\"\}"
  403.     } {
  404.       append xfArguments " $xfArg"
  405.     }
  406.   }
  407.   set xfBodyList [string trimright [info body $xfProcName]]
  408.  
  409.   if {[XFMiscIsXFElement $xfProcName] ||
  410.       ![XFMiscCorrectLevel procsave $xfBodyList]} {
  411.     return
  412.   }
  413.  
  414.   puts $xfOutFile "\n" 
  415.   XFSaveComment $xfOutFile proc $xfProcName
  416.   # write procedure
  417.   if {[XFMiscIsXFSpecialElement $xfProcName]} {
  418.     puts $xfOutFile "if {\"\[info procs $xfProcName\]\" == \"\"} {"
  419.     puts $xfOutFile "proc $xfProcName {$xfArguments} {"
  420.     if {[string index $xfBodyList 0] == "\n"} {
  421.       puts $xfOutFile [string range $xfBodyList 1 end]
  422.     } {
  423.       puts $xfOutFile $xfBodyList
  424.     }
  425.     puts $xfOutFile "}"
  426.     puts $xfOutFile "}"
  427.   } {
  428.     puts $xfOutFile "proc $xfProcName {$xfArguments} {"
  429.     if {[string index $xfBodyList 0] == "\n"} {
  430.       puts $xfOutFile [string range $xfBodyList 1 end]
  431.     } {
  432.       puts $xfOutFile $xfBodyList
  433.     }
  434.     puts $xfOutFile "}"
  435.   }
  436. }
  437.  
  438. ##########
  439. # Procedure: XFSaveRootToplevelChild
  440. # Description: save the a child widget of .
  441. # Arguments: xfOutFile - the output descriptor
  442. #            xfName - the name of the window
  443. # Returns: none
  444. # Sideeffects: none
  445. ##########
  446. proc XFSaveRootToplevelChild {xfOutFile xfName} {
  447.   global xfAppDefToplevels
  448.   global xfMisc
  449.  
  450.   set xfMisc(menuBarTraversalList) ""
  451.   set xfMisc(specialSaveString) ""
  452.   puts $xfOutFile "\n\n# procedure to show window $xfName"
  453.   puts $xfOutFile "proc ShowWindow$xfName {args} {# xf ignore me 7"
  454.   if {"[info procs StartupSrc$xfName]" != ""} {
  455.     puts $xfOutFile "\nStartupSrc$xfName"
  456.   }
  457.   XFSaveWidget $xfOutFile $xfName
  458.   XFSaveBind $xfOutFile $xfName
  459.   XFSaveWidgetSpecial $xfOutFile $xfName
  460.   XFSaveSubwindow $xfOutFile $xfName
  461.   if {"[info procs MiddleSrc$xfName]" != ""} {
  462.     puts $xfOutFile "\nMiddleSrc$xfName"
  463.   }
  464.   XFSavePack $xfOutFile $xfName
  465.   XFSavePlace $xfOutFile $xfName
  466.   XFSaveMenubarTraversal $xfOutFile
  467.   if {[lsearch $xfAppDefToplevels $xfName] != -1} {
  468.     puts $xfOutFile "  if {\"\[info procs XFLocalSetAppDefs\]\" != \"\"} {"
  469.     puts $xfOutFile "    XFLocalSetAppDefs"
  470.     puts $xfOutFile "  }"
  471.   }
  472.   if {"$xfMisc(specialSaveString)" != ""} {
  473.     puts $xfOutFile "\n$xfMisc(specialSaveString)\n"
  474.   }
  475.   if {"[info procs EndSrc$xfName]" != ""} {
  476.     puts $xfOutFile "\nEndSrc$xfName"
  477.   }
  478.   puts $xfOutFile "\n  if {\"\[info procs XFEdit\]\" != \"\"} {"
  479.   puts $xfOutFile "    catch \"XFMiscBindWidgetTree $xfName\""
  480.   puts $xfOutFile "    after 2 \"catch \{XFEditSetShowWindows\}\""
  481.   puts $xfOutFile "  }"
  482.   puts $xfOutFile "}"
  483. }
  484.  
  485. ##########
  486. # Procedure: XFSaveShowWindow
  487. # Description: save the show window procedure
  488. # Arguments: xfOutFile - the output descriptor
  489. #            xfName - the name of the window
  490. # Returns: none
  491. # Sideeffects: none
  492. ##########
  493. proc XFSaveShowWindow {xfOutFile xfName} {
  494.  
  495.   set xfCounter xfShowWindow[string range $xfName 10 \
  496.     [expr [string length $xfName]-1]]
  497.   if {"[info globals $xfCounter]" != ""} {
  498.     global $xfCounter
  499.     if {[set $xfCounter] == 0} {
  500.       set xfWinName [string range $xfCounter 13 end]
  501.       # get arg list for procedure
  502.       set xfArgList [info args $xfName]
  503.       set xfArguments ""
  504.       foreach xfArg $xfArgList {
  505.         if {[info default $xfName $xfArg xfDefault]} {
  506.           set xfArguments "$xfArguments \{$xfArg \"$xfDefault\"\}"
  507.         } {
  508.           set xfArguments "$xfArguments $xfArg"
  509.         }
  510.       }
  511.       # get procedure body
  512.       set xfBodyList [string trimright [info body $xfName]]
  513.       puts $xfOutFile "\n\n# procedure to show window $xfName"
  514.       puts $xfOutFile "proc $xfName {$xfArguments} {"
  515.       if {[string index $xfBodyList 0] == "\n"} {
  516.         puts $xfOutFile [string range $xfBodyList 1 end]
  517.       } {
  518.         puts $xfOutFile $xfBodyList
  519.       }
  520.       puts $xfOutFile "}"
  521.       XFSaveSourceDestroyWindow $xfOutFile .$xfWinName
  522.       XFSaveShowWindowTail $xfOutFile .$xfWinName
  523.     }
  524.   }
  525. }
  526.  
  527. ##########
  528. # Procedure: XFSaveShowWindowTail
  529. # Description: save the appendix of the show window procedure
  530. # Arguments: xfOutFile - the output descriptor
  531. #            xfWinName - the name of the window
  532. # Returns: none
  533. # Sideeffects: none
  534. ##########
  535. proc XFSaveShowWindowTail {xfOutFile xfWinName} {
  536.  
  537.   if {"[info procs StartupSrc$xfWinName]" != ""} {
  538.     set xfBodyList [string trimright [info body StartupSrc$xfWinName]]
  539.     puts $xfOutFile "\nproc StartupSrc$xfWinName {args} {"
  540.     if {[string index $xfBodyList 0] == "\n"} {
  541.       puts $xfOutFile [string range $xfBodyList 1 end]
  542.     } {
  543.       puts $xfOutFile $xfBodyList
  544.     }
  545.     puts $xfOutFile "}"
  546.   }
  547.   if {"[info procs MiddleSrc$xfWinName]" != ""} {
  548.     set xfBodyList [string trimright [info body MiddleSrc$xfWinName]]
  549.     puts $xfOutFile "\nproc MiddleSrc$xfWinName {} {"
  550.     if {[string index $xfBodyList 0] == "\n"} {
  551.       puts $xfOutFile [string range $xfBodyList 1 end]
  552.     } {
  553.       puts $xfOutFile $xfBodyList
  554.     }
  555.     puts $xfOutFile "}"
  556.   }
  557.   if {"[info procs EndSrc$xfWinName]" != ""} {
  558.     set xfBodyList [string trimright [info body EndSrc$xfWinName]]
  559.     puts $xfOutFile "\nproc EndSrc$xfWinName {} {"
  560.     if {[string index $xfBodyList 0] == "\n"} {
  561.       puts $xfOutFile [string range $xfBodyList 1 end]
  562.     } {
  563.       puts $xfOutFile $xfBodyList
  564.     }
  565.     puts $xfOutFile "}"
  566.   }
  567. }
  568.  
  569. ##########
  570. # Procedure: XFSaveSubwindowBuild
  571. # Description: save the subwindows
  572. # Arguments: xfOutFile - the output descriptor
  573. #            xfParent - the parent widget
  574. # Returns: none
  575. # Sideeffects: none
  576. ##########
  577. proc XFSaveSubwindowBuild {xfOutFile xfParent} {
  578.  
  579.   foreach xfCounter [winfo children $xfParent] {
  580.     if {![string match ".xf*" $xfCounter] &&
  581.         ![string match "xf*" [winfo name $xfCounter]] &&
  582.         !($xfParent == "." && [winfo class $xfCounter] == "Toplevel")} {
  583.       XFSaveWidget $xfOutFile $xfCounter
  584.       XFSaveBind $xfOutFile $xfCounter
  585.       XFSaveWidgetSpecial $xfOutFile $xfCounter
  586.       XFSaveSubwindowBuild $xfOutFile $xfCounter
  587.     }
  588.   }
  589. }
  590.  
  591. ##########
  592. # Procedure: XFSaveSubwindowGeometry
  593. # Description: save the subwindows geometry
  594. # Arguments: xfOutFile - the output descriptor
  595. #            xfParent - the parent widget
  596. # Returns: none
  597. # Sideeffects: none
  598. ##########
  599. proc XFSaveSubwindowGeometry {xfOutFile xfParent} {
  600.  
  601.   foreach xfCounter [winfo children $xfParent] {
  602.     if {![string match ".xf*" $xfCounter] &&
  603.         ![string match "xf*" [winfo name $xfCounter]] &&
  604.         !($xfParent == "." && [winfo class $xfCounter] == "Toplevel")} {
  605.       XFSavePack $xfOutFile $xfCounter
  606.       XFSavePlace $xfOutFile $xfCounter
  607.       XFSaveSubwindowGeometry $xfOutFile $xfCounter
  608.     }
  609.   }
  610. }
  611.  
  612. ##########
  613. # Procedure: XFSaveSubwindow
  614. # Description: save the subwindows
  615. # Arguments: xfOutFile - the output descriptor
  616. #            xfParent - the parent widget
  617. # Returns: none
  618. # Sideeffects: none
  619. ##########
  620. proc XFSaveSubwindow {xfOutFile xfParent} {
  621.   global xfConf
  622.  
  623.   if {$xfConf(newPacker)} {
  624.     if {![string match ".xf*" $xfParent] &&
  625.         ("$xfParent" == "." || ![string match "xf*" [winfo name $xfParent]])} {
  626.       XFSaveSubwindowBuild $xfOutFile $xfParent
  627.       XFSaveSubwindowGeometry $xfOutFile $xfParent
  628.     }
  629.   } {
  630.     if {![string match ".xf*" $xfParent] &&
  631.         ("$xfParent" == "." || ![string match "xf*" [winfo name $xfParent]])} {
  632.       # xfS is a hack to build scrollbars before other classes.
  633.       # This was necessary before Tk 3.3, because some classes would
  634.       # execute their scrollcommands as they were created.  I don't
  635.       # think is a problem now, but just to be safe...
  636.       foreach xfS {1 0} {
  637.         foreach xfCounter [winfo children $xfParent] {
  638.           # save everything except scrollbars
  639.           if {![string match ".xf*" $xfCounter] &&
  640.               ![string match "xf*" [winfo name $xfCounter]] && 
  641.               !($xfParent == "." && [winfo class $xfCounter] == "Toplevel") &&
  642.               $xfS == ([winfo class $xfCounter] == "Scrollbar")} {
  643.             XFSaveWidget $xfOutFile $xfCounter
  644.             XFSaveBind $xfOutFile $xfCounter
  645.             XFSaveWidgetSpecial $xfOutFile $xfCounter
  646.             XFSaveSubwindow $xfOutFile $xfCounter
  647.             XFSavePack $xfOutFile $xfCounter
  648.             XFSavePlace $xfOutFile $xfCounter
  649.           }
  650.         }
  651.       }
  652.     }
  653.   }
  654. }
  655.  
  656. ##########
  657. # Procedure: XFSaveWidget
  658. # Description: save widget
  659. # Arguments: xfOutFile - the output descriptor
  660. #            xfW - the widget
  661. # Returns: none
  662. # Sideeffects: none
  663. ##########
  664. proc XFSaveWidget {xfOutFile xfW} {
  665.   global xfConf
  666.   global xfNoWidgetSave
  667.   global xfPath
  668.  
  669.   if {"$xfW" == "."} {
  670.     set xfClass Toplevel
  671.   } {
  672.     set xfClass [winfo class $xfW]
  673.   }
  674.   if {[lsearch $xfNoWidgetSave $xfClass] == -1} {
  675.     if {"[info procs XFSaveWidget.$xfClass]" == ""} {
  676.       if {[file exists "$xfPath(elements)/$xfClass"]} {
  677.         source "$xfPath(elements)/$xfClass"
  678.       } {
  679.         foreach xfPathElement [split $xfPath(additionals) :] {
  680.           if {[XFMiscIsDir $xfPathElement]} {
  681.             if {[file exists "$xfPathElement/$xfClass"]} {
  682.               source "$xfPathElement/$xfClass"
  683.               break
  684.             }
  685.           }
  686.         }
  687.       }
  688.     }
  689.   }
  690.   if {"[info procs XFSaveWidget.$xfClass]" != ""} {
  691.     XFSaveWidget.$xfClass $xfOutFile $xfW
  692.   } {
  693.     # what are we doing here ?
  694.     puts $xfOutFile "\n  # build widget $xfW"
  695.  
  696.     set xfUseConfig 1
  697.     # write widget type and path name
  698.     case $xfClass in {
  699.       {Button Canvas Checkbutton Entry Frame Label Listbox Menu Menubutton Message Radiobutton Scale Scrollbar Text Toplevel} {
  700.         puts $xfOutFile "  [string tolower $xfClass] $xfW" nonewline
  701.         set xfUseConfig 0
  702.       }
  703.       {default} {
  704.         set xfType [string tolower [string index $xfClass 0]]
  705.         append xfType [string range $xfClass 1 end]
  706.         if {"[info commands $xfType]" == ""} {
  707.           set xfType [string tolower $xfClass]
  708.         }
  709.  
  710.         puts $xfOutFile "  if {\[catch \"$xfType $xfW\"\]} {"
  711.         puts $xfOutFile "    if {\"\[info procs XFEdit\]\" != \"\"} {"
  712.         puts $xfOutFile "      XFProcError \"Unknown widget type: $xfType\""
  713.         puts $xfOutFile "      return"
  714.         puts $xfOutFile "    } {"
  715.         puts $xfOutFile "      puts stderr \"Unknown widget type: $xfType\""
  716.         puts $xfOutFile "      catch \"destroy .\""
  717.         puts $xfOutFile "      catch \"exit 0\""
  718.         puts $xfOutFile "    }"
  719.         puts $xfOutFile "  }"
  720.       }
  721.     }
  722.  
  723.     # write options
  724.     if {$xfUseConfig} {
  725.       puts $xfOutFile "  $xfW config" nonewline
  726.     }
  727.     XFSaveWidgetResource $xfOutFile $xfW
  728.     puts $xfOutFile ""
  729.   }
  730. }
  731.  
  732. ##########
  733. # Procedure: XFSaveWidgetResource
  734. # Description: save widget resource values
  735. # Arguments: xfOutFile - the output descriptor
  736. #            xfW - the widget
  737. # Returns: none
  738. # Sideeffects: none
  739. ##########
  740. proc XFSaveWidgetResource {xfOutFile xfW} {
  741.   global xfConf
  742.  
  743.   foreach xfCounter [$xfW config] {
  744.     # only handle options with 5 items per option entry
  745.     if {[llength $xfCounter] == 5} {
  746.       if {("[lindex $xfCounter 0]" == "-xscrollcommand" ||
  747.            "[lindex $xfCounter 0]" == "-yscrollcommand" ||
  748.            "[lindex $xfCounter 0]" == "-scrollcommand") &&
  749.            "[lindex $xfCounter 4]" == "NoFunction"} {
  750.         continue
  751.       }
  752.       if {("[winfo class $xfW]" == "Scale" ||
  753.            "[winfo class $xfW]" == "Scrollbar") &&
  754.            "[lindex $xfCounter 0]" == "-command" &&
  755.            "[lindex $xfCounter 4]" == "NoFunction"} {
  756.         continue
  757.       }
  758.       if {"[lindex $xfCounter 3]" != "[lindex $xfCounter 4]"} {
  759.         if {$xfConf(encloseConfigure)} {
  760.           puts $xfOutFile " \\\n    [lindex $xfCounter 0] {[lindex $xfCounter 4]}" nonewline
  761.         } {
  762.           puts $xfOutFile " \\\n    [lindex $xfCounter 0] \"[lindex $xfCounter 4]\"" nonewline
  763.         }
  764.       }
  765.     }
  766.   }
  767. }
  768.  
  769. ##########
  770. # Procedure: XFSaveWidgetSpecial
  771. # Description: save widget specific code
  772. # Arguments: xfOutFile - the output descriptor
  773. #            xfW - the widget
  774. # Returns: none
  775. # Sideeffects: none
  776. ##########
  777. proc XFSaveWidgetSpecial {xfOutFile xfW} {
  778.   global xfNoSpecialSave
  779.   global xfMisc
  780.   global xfPath
  781.  
  782.   if {"$xfW" == "."} {
  783.     set xfClass Toplevel
  784.   } {
  785.     set xfClass [winfo class $xfW]
  786.   }
  787.   if {[lsearch $xfNoSpecialSave $xfClass] == -1} {
  788.     if {"[info procs XFSaveSpecial.$xfClass]" == ""} {
  789.       if {[file exists "$xfPath(elements)/$xfClass"]} {
  790.         source "$xfPath(elements)/$xfClass"
  791.       } {
  792.         foreach xfPathElement [split $xfPath(additionals) :] {
  793.           if {[XFMiscIsDir $xfPathElement]} {
  794.             if {[file exists "$xfPathElement/$xfClass"]} {
  795.               source "$xfPathElement/$xfClass"
  796.               break
  797.             }
  798.           }
  799.         }
  800.       }
  801.     }
  802.     if {"[info procs XFSaveSpecial.$xfClass]" != ""} {
  803.       append xfMisc(specialSaveString) [XFSaveSpecial.$xfClass $xfW]
  804.     }
  805.   }
  806. }
  807.  
  808. # eof
  809.  
  810.